package com.eddy.mapper;

import com.eddy.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


@Mapper
public interface UserMapper {
    @Select("SELECT * FROM `user` WHERE UserName = #{username} AND `Password` = #{password} AND State = 1")
    User getUserMessage(@Param("username") String username,@Param("password")  String password);

    //批量查询，不返回密码
    @Select("SELECT Id,UserName,Email,Role,State FROM `user` WHERE UserName like concat('%',#{username},'%') LIMIT #{pageStart},#{pageSize}")
    List<User> getAllUser(@Param("username") String username,@Param("pageStart") int pageStart,@Param("pageSize") int pageSize);

    @Select("SELECT Count(*) FROM `user` WHERE UserName like concat('%',#{username},'%')")
    int getUserTotal(@Param("username") String username);

    @Update("UPDATE `user` SET State = #{state} WHERE Id = #{id}")
    int updateState(@Param("id") Integer id,@Param("state") Integer state);

    @Insert("INSERT INTO `user`(UserName,`Password`,Email,Role,State) VALUES(#{username},#{password},#{email},#{role},#{state})")
    int addUser(@RequestBody User user);

    @Delete("DELETE FROM `User` WHERE Id = #{id}")
    int deleteUser(@Param("id") Integer id);

    @Select("SELECT * FROM `user` WHERE Id = #{id}")
    User getUser(@Param("id") Integer id);

    @Update("UPDATE `user` SET `Password` = #{password},`Email` = #{email},Role = #{role} WHERE Id = #{id}")
    int updateUser(@RequestBody User user);
}
